package dao.impl;

import dao.Basedao;
import dao.Userdao;
import enity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Userdaoimpl extends Basedao implements Userdao {
    private Connection conn;
    private PreparedStatement pre;
    private ResultSet resultSet;
    @Override
    public User login(User user) {

        try {
            conn=getconnection();
            String sql="select*from `student` where LoginPwd=? and StudentName=?";
            pre=conn.prepareStatement(sql);
            pre.setObject(1,user.getPwd());
            pre.setObject(2,user.getUsername());
            resultSet=pre.executeQuery();
            User lo=null;
            if(resultSet.next()){
                lo=new User();
                lo.setPwd(resultSet.getString("LoginPwd"));
                lo.setUsername(resultSet.getString("StudentName"));
            }
            return lo;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
